from django.db import models

# Create your models here.
class Poll(models.Model):
    question  = models.CharField(max_length=200)
    comments  = models.BooleanField(default=True)
    published = models.BooleanField(default=True)
    pub_date  = models.DateTimeField('date published')

    def __unicode__(self):
                return self.question
            
class Choice(models.Model):
    poll = models.ForeignKey(Poll)
    choice = models.CharField(max_length=200)
    votes = models.IntegerField()

    def __unicode__(self):
                return self.choice

from django.contrib import admin

class ChoiceInline(admin.TabularInline):
        model = Choice
        extra = 3

class PollAdmin(admin.ModelAdmin):
        fieldsets = [
              (None,               {'fields': ['question']}),
              ('Date information', {'fields': ['pub_date'], 'classes': ['collapse']}),
                    ]
        inlines      = [ChoiceInline]
        #list_display = ('question', 'pub_date', 'was_published_today')
        list_filter  = ['pub_date']
        search_fields = ['question']
        date_hierarchy = 'pub_date'
        
        def was_published_today(self):
                return self.pub_date.date() == datetime.date.today()
        was_published_today.short_description = 'Published today?'

admin.site.register(Poll, PollAdmin)
